package com.txy.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.txy.service.HelloService;
import com.txy.util.HttpRequestUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    @Reference(loadbalance = "roundrobin")
    private HelloService helloService;

    @GetMapping("/hello")
    public String hello(HttpServletRequest request) {
        RpcContext.getContext().setAttachment("realIp", HttpRequestUtil.getRealIp(request));
        return helloService.sayHello("abc");
    }
}
